package le.ralph.quwen.cn.java.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import java.util.List;

import le.ralph.quwen.cn.R;
import le.ralph.quwen.cn.java.view.adapter.RvAdapter;
import le.ralph.quwen.cn.java.model.bean.UserInfo;
import le.ralph.quwen.cn.java.view.widget.OnViewPagerListener;
import le.ralph.quwen.cn.java.view.widget.ViewPagerLayoutManager;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";
    private RecyclerView mRecyclerView;
    private RvAdapter mAdapter;
    private ViewPagerLayoutManager mLayoutManager;
    private List<UserInfo> userInfos;
    private TextView tvMainUser;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initListener();
    }

    private void initView() {
        mRecyclerView = findViewById(R.id.recycler);
        mLayoutManager = new ViewPagerLayoutManager(this, OrientationHelper.VERTICAL);
        mAdapter = new RvAdapter(this, userInfos);
        mRecyclerView.setLayoutManager(mLayoutManager);
        mRecyclerView.setAdapter(mAdapter);

        tvMainUser = findViewById(R.id.tv_main_user);
    }

    private void initListener() {
        mLayoutManager.setOnViewPagerListener(new OnViewPagerListener() {
            @Override
            public void onPageRelease(boolean isNext, int position) {
                Log.e(TAG, "释放位置:" + position + " 下一页:" + isNext);
            }

            @Override
            public void onPageSelected(int position, boolean isBottom) {
                Log.e(TAG, "选中位置:" + position + "  是否是滑动到底部:" + isBottom);
            }

            @Override
            public void onLayoutComplete() {

            }

        });
        tvMainUser.setOnClickListener(defaultOnClickListener);
    }

    private View.OnClickListener defaultOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int id = v.getId();
            switch (id) {
                case R.id.tv_main_user:
                    Intent intent = new Intent(MainActivity.this, RegisterActivity.class);
                    startActivity(intent);
                    break;
            }
        }
    };
}
